package com.tedu.cooshark.controller;

import com.tedu.cooshark.entity.Category;
import com.tedu.cooshark.service.CategroyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 2022/3/24  14:16
 */
@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategroyService categroyService;
    @RequestMapping("/selectall")
    public List<Category> selectall(){
        return categroyService.selectAll();
    }
    @RequestMapping("/deleteById")
    public int deleteById(int id){
        int i = categroyService.deleteById(id);
        return i;
    }
    @RequestMapping("/selectById")
    public Category selectById(int id){
        return categroyService.selectById(id);
    }
    @RequestMapping("/updateCategory")
    public int updateCategory(@RequestBody Category category){
        try {
            return categroyService.updateCategory(category);
        } catch (Exception e) {
            return 0;
        }
    }
    @RequestMapping("/addCategory")
    public int insert(@RequestBody Category category){
        try {
            return categroyService.insert(category);
        } catch (Exception e) {
            return 0;
        }
    }
    @RequestMapping("/deleteByids")
    public int deleteByids(@RequestBody List<Category> categorys){
        return categroyService.deleteByIds(categorys);
    }
}
